﻿
#region 程序集引用区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SubSonic.DataProviders;
using SubSonic.Extensions;
using System.Linq.Expressions;
using SubSonic.Schema;
using System.Collections;
using SubSonic;
using SubSonic.Repository;
using System.ComponentModel;
using System.Data.Common;
using SubSonic.Query;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;

//引用实体层
using WebeTerm.Model;
using WebeTerm.Common;
#endregion

namespace WebeTerm.DbProvider{
    /// <summary>
    /// 文 件 名: ConfigurationInfoDAL.cs
    /// CLR版本 : v2.0.50727
    /// 作   者 : lijun.hu
    /// 版    权: Copyright @2011 lijun.hu(FORCEN HU) 
    /// 电子邮箱：lijun.hu@shinsoft.net
    /// 说    明: eTerm配置信息
    /// 生成日期: 2014年12月5日
    /// </summary>
    public partial class ConfigurationInfoDAL:BaseDAL< ConfigurationInfo >{
        
        #region 通用查询
        /// <summary>
        /// 查询系统设置
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="pages">分页信息</param>
        /// <returns>系统设置</returns>
        public List< ConfigurationInfo > SearchConfigurationInfo(ConfigurationInfoQuery queryParam, Pages pages)
        {
            IQueryable< ConfigurationInfo > iQuery = QueryConfigurationInfo(queryParam);
            var items = base.SplitPage(iQuery, pages).ToList();
            items.ForEach(l=>{
                { if (l is IModel) { (l as IModel).SetIsLoaded(); } }    
            });
            return items;
        }

        /// <summary>
        /// 计算系统设置数
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>系统设置数</returns>
        public int SearchConfigurationInfoCount(ConfigurationInfoQuery queryParam)
        {
            return QueryConfigurationInfo(queryParam).Count();
        } 
        #endregion

        #region 组合查询
        /// <summary>
        /// 设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>eTerm配置信息</returns>
        public IQueryable< ConfigurationInfo > QueryConfigurationInfo(ConfigurationInfoQuery queryParam)
        {
            IQueryable<ConfigurationInfo> iQuery = All();
            iQuery = QueryConfigurationInfoById(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByCompanyId(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByEmployeeId(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByConfigType(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByConfigAddress(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByConfigPort(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByConfigUserName(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByConfigUserPassword(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByConfigRID(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByConfigSID(queryParam, iQuery);
            iQuery = QueryConfigurationInfoBySiText(queryParam, iQuery);
            iQuery = QueryConfigurationInfoByStatusId(queryParam, iQuery);
            return iQuery;
        }
        #endregion
        
        #region 单条件查询
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoById(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (queryParam.Id != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.Id == queryParam.Id);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByCompanyId(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (queryParam.CompanyId != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.CompanyId == queryParam.CompanyId);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByEmployeeId(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (queryParam.EmployeeId != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.EmployeeId == queryParam.EmployeeId);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByConfigType(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (queryParam.ConfigType != (int)0)
                iQuery = iQuery.Where(iq => iq.ConfigType == queryParam.ConfigType);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByConfigAddress(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.ConfigAddress))
                iQuery = iQuery.Where(iq => iq.ConfigAddress.Contains(queryParam.ConfigAddress.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByConfigPort(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (queryParam.ConfigPort != (int)0)
                iQuery = iQuery.Where(iq => iq.ConfigPort == queryParam.ConfigPort);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByConfigUserName(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.ConfigUserName))
                iQuery = iQuery.Where(iq => iq.ConfigUserName.Contains(queryParam.ConfigUserName.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByConfigUserPassword(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.ConfigUserPassword))
                iQuery = iQuery.Where(iq => iq.ConfigUserPassword.Contains(queryParam.ConfigUserPassword.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByConfigRID(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (queryParam.ConfigRID != (int)0)
                iQuery = iQuery.Where(iq => iq.ConfigRID == queryParam.ConfigRID);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByConfigSID(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (queryParam.ConfigSID != (int)0)
                iQuery = iQuery.Where(iq => iq.ConfigSID == queryParam.ConfigSID);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoBySiText(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.SiText))
                iQuery = iQuery.Where(iq => iq.SiText.Contains(queryParam.SiText.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 eTerm配置信息 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">eTerm配置信息 查询</param>
        /// <returns>eTerm配置信息 查询</returns>
        protected virtual IQueryable< ConfigurationInfo > QueryConfigurationInfoByStatusId(ConfigurationInfoQuery queryParam, IQueryable< ConfigurationInfo > iQuery)
        {
            if (queryParam.StatusId != (int)0)
                iQuery = iQuery.Where(iq => iq.StatusId == queryParam.StatusId);
            return iQuery;
        }
        #endregion
    }
}    